<template>
  <div>
    <van-checkbox-group v-model="ids">
      <van-checkbox :name="i.id" v-for="i in resourcelist" :key="i">{{i.name}}</van-checkbox>
    </van-checkbox-group>
    <button @click="add_data">提交</button>
  </div>
</template>

<script>
import axios from '../../http/axios'
export default {
  data() {
    return {
      id: localStorage.getItem('userid'),
      ids: [],
      resourcelist: [],
    };
  },
  methods: {
    getroles() {
      axios("/resourse?userid=" + this.id,'get').then(res => {
        console.log(res);
        this.ids = res.list;
      });
    },
    getresout() {
      axios("/resourse",'get').then(res => {
        console.log(res);
        this.resourcelist = res.list;
        this.getroles()
      });
    },
    add_data(){
        console.log(this.id);
        console.log(this.ids);
      axios('/resourse','post',{'userid':this.id,'ids':this.ids}).then(res=>{
        console.log(res)
      })
    }
  },
  mounted() {
    this.getresout();
  },
};
</script>

<style>
</style>